package com.ruoyi.project.WebMoudle.shopPick.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.WebMoudle.ShopSuser.domain.ShopSuser;
import com.ruoyi.project.WebMoudle.ShopSuser.service.IShopSuserService;
import com.ruoyi.project.WebMoudle.shopPick.domain.PickSum;
import com.ruoyi.project.WxMoudle.Bases.PickMoney;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.shopPick.domain.ShopPick;
import com.ruoyi.project.WebMoudle.shopPick.service.IShopPickService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商家提现Controller
 * 
 * @author ruoyi
 * @date 2020-07-17
 */
@Controller
@RequestMapping("/shopPick/shopPick")
public class ShopPickController extends BaseController
{
    private String prefix = "shopPick/shopPick";

    @Autowired
    private IShopPickService shopPickService;
    @Autowired
    private IShopSuserService shopSuserService;

    @RequiresPermissions("shopPick:shopPick:view")
    @GetMapping()
    public String shopPick()
    {
        return prefix + "/shopPick";
    }

    /**
     * 查询商家提现列表
     */
    @RequiresPermissions("shopPick:shopPick:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopPick shopPick)
    {
        startPage();
        List<ShopPick> list = shopPickService.selectShopPickList(shopPick);
        PickSum pickSum = shopPickService.queryMoneySum(shopPick);
        if (!StringUtils.isNotNull(pickSum)){
            pickSum = new PickSum();
        }
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        rspData.setPickSum(pickSum);
        return rspData;
    }

    /**
     * 导出商家提现列表
     */
    @RequiresPermissions("shopPick:shopPick:export")
    @Log(title = "商家提现", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopPick shopPick)
    {
        List<ShopPick> list = shopPickService.selectShopPickList(shopPick);
        ExcelUtil<ShopPick> util = new ExcelUtil<ShopPick>(ShopPick.class);
        return util.exportExcel(list, "shopPick");
    }

    /**
     * 新增商家提现
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商家提现
     */
    @RequiresPermissions("shopPick:shopPick:add")
    @Log(title = "商家提现", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopPick shopPick)
    {
        return toAjax(shopPickService.insertShopPick(shopPick));
    }

    /**
     * 修改商家提现
     */
    @GetMapping("/edit/{orderNum}")
    public String edit(@PathVariable("orderNum") String orderNum, ModelMap mmap)
    {
        ShopPick shopPick = shopPickService.selectShopPickById(orderNum);
        mmap.put("shopPick", shopPick);
        return prefix + "/edit";
    }

    /**
     * 修改保存商家提现
     */
    @RequiresPermissions("shopPick:shopPick:edit")
    @Log(title = "商家提现", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopPick shopPick)
    {
        return toAjax(shopPickService.updateShopPick(shopPick));
    }

    /**
     * 删除商家提现
     */
    @RequiresPermissions("shopPick:shopPick:remove")
    @Log(title = "商家提现", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopPickService.deleteShopPickByIds(ids));
    }


    /*修改状态*/
    @RequiresPermissions("shopPick:shopPick:edit")
    @Log(title = "商家提现", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    @Transactional
    public AjaxResult changeStatus(ShopPick shopPick)
    {
        ShopPick sp = shopPickService.selectShopPickById(shopPick.getOrderNum());

        if (shopPick.getStatus().equals("1")){    //通过申请

        }

        return toAjax(shopPickService.updateShopPick(shopPick));
    }

}
